package com.yt.base.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.yt.base.model.AclCategory;
import com.yt.base.model.AclOperation;
import com.yt.base.model.AclPrivilege;

public class UserMenuVo implements Serializable {
	private static final long serialVersionUID = 1L;

	private List<AclCategory> categoryList = new ArrayList<AclCategory>();

	private Map<Long, List<AclPrivilege>> privilegeMap = new HashMap<Long, List<AclPrivilege>>();

	private Map<String, List<AclOperation>> operationMap = new HashMap<String, List<AclOperation>>();

	private Set<String> operationKeys = new HashSet<String>();

	public void addCategory(AclCategory category) {
		if (category == null)
			return;
		categoryList.add(category);
	}

	public void addPrividege(AclPrivilege privilege) {
		if (privilege == null)
			return;

		List<AclPrivilege> privilegeList = privilegeMap.get(privilege.getCategoryId());
		if (privilegeList == null) {
			privilegeList = new ArrayList<AclPrivilege>();
			privilegeMap.put(privilege.getCategoryId(), privilegeList);
		}
		privilegeList.add(privilege);
	}

	public void addOperation(AclOperation operation) {
		if (operation == null)
			return;
		String key = operation.getCategoryId() + "_" + operation.getPrivilegeId();
		List<AclOperation> operationList = operationMap.get(key);
		if (operationList == null) {
			operationList = new ArrayList<AclOperation>();
			operationMap.put(key, operationList);
		}
		operationList.add(operation);

	}

	public List<AclOperation> getOperationList(Long categoryId, Long privilegeId) {
		return operationMap.get(categoryId + "_" + privilegeId);
	}

	public List<AclPrivilege> getPrivilegeList(Long categoryId) {
		return privilegeMap.get(categoryId);
	}

	public List<AclCategory> getCategoryList() {
		return this.categoryList;
	}

	public void putOperationKeys(String key) {
		if (key == null)
			return;
		operationKeys.add(key);
	}

	public boolean checkPermission(String key) {
		if (operationKeys.contains(key)) {
			return true;
		}
		return false;
	}
}
